package calculate24.play.AutoCalculate;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import calculate24.play.common.card.Card;

//存储选中的卡片，并显示在界面头部
class PickedCards {
    private ImageView[] slots;
    private Card[] cards;
    private int count;

    public PickedCards(@NonNull ImageView... slots) {
        this.slots = slots;
        cards = new Card[slots.length];
        count = 0;
    }

    public boolean add(Card card) {
        boolean succeed = false;
        for(int i = 0; i < slots.length; ++i) {
            if(cards[i] == null) {
                cards[i] = card;
                slots[i].setImageDrawable(cards[i].view.getDrawable());
                count++;
                succeed = true;
                break;
            }
        }
        return succeed;
    }

    public boolean remove(Card card) {
        boolean succeed = false;
        for(int i = 0; i < slots.length; ++i) {
            if(cards[i] != null && cards[i].equals(card)) {
                cards[i] = null;
                slots[i].setImageDrawable(null);
                count--;
                succeed = true;
                break;
            }
        }
        return succeed;
    }

    public boolean isFull() {
        return count == slots.length;
    }
    
    public int[] allNumbers() {
        int[] numbers = new int[slots.length];
        for(int i = 0; i < slots.length; ++i) {
            if(cards[i] != null) {
                numbers[i] = cards[i].number;
            }
        }
        return numbers;
    }

}
